package com.example.tianxi.yuexiuhhpatient;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

public class HistoryInfoActivity extends Activity implements View.OnClickListener{


    //more的菜单栏
    private TextView more;
    private TextView back;

    private TextView textView1;
    private TextView textView2;
    private TextView textView3;
    private TextView textView4;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_history_info);
//        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
//        //设置tiilbar的内容
//        toolbar.setNavigationContentDescription("返回");
//        toolbar.setTitle("查看病历");
//        toolbar.setMenu();
//        setSupportActionBar(toolbar);

//        FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
//        fab.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
//                Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
//                        .setAction("Action", null).show();
//            }
//        });

        initView();
    }

    public void initView(){
        more = (TextView)findViewById(R.id.history_info_more);
        back = (TextView)findViewById(R.id.history_info_back);

        more.setOnClickListener(this);
        back.setOnClickListener(this);

        textView1 = (TextView)findViewById(R.id.textView1);
        textView2 = (TextView)findViewById(R.id.textView2);
        textView3 = (TextView)findViewById(R.id.textView3);
        textView4 = (TextView)findViewById(R.id.textView4);

        textView1.setText(getIntent().getStringExtra("textview1"));
        textView2.setText(getIntent().getStringExtra("textview2"));
        textView3.setText(getIntent().getStringExtra("textview3"));
        textView4.setText(getIntent().getStringExtra("textview4"));

    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.historyinfo_menu, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        return super.onOptionsItemSelected(item);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.history_info_more:

                LinearLayout layout = (LinearLayout)getLayoutInflater().inflate(R.layout.history_info_more_dialog, null);
                new AlertDialog.Builder(this)
                        .setIcon(null)
                        .setView(layout)
                        .create()
                        .show();

                TextView edit = (TextView)layout.findViewById(R.id.edit);
                edit.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Toast.makeText(getApplicationContext(), "点击了编辑", Toast.LENGTH_LONG).show();
                        Intent intent = new Intent(HistoryInfoActivity.this,EditHistoryInfoActivity.class);
                        intent.putExtra("flag",true);//设置true表示编辑，需要将页面数据传过去
                        intent.putExtra("textview1",getIntent().getStringExtra("textview1"));
                        intent.putExtra("textview2",getIntent().getStringExtra("textview2"));
                        intent.putExtra("textview3",getIntent().getStringExtra("textview3"));
                        intent.putExtra("textview4",getIntent().getStringExtra("textview4"));
                        startActivity(intent);//这里应该使用startActivityForResult，带有编辑后的返回值，再改
                        finish();
                    }
                });
                TextView delete = (TextView)layout.findViewById(R.id.delete);
                delete.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Toast.makeText(getApplicationContext(),"点击了删除",Toast.LENGTH_LONG).show();
                        finish();
                    }
                });
                TextView send = (TextView)layout.findViewById(R.id.send);
                send.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Toast.makeText(getApplicationContext(),"点击了发送",Toast.LENGTH_LONG).show();
                        finish();
                    }
                });
                break;

            case R.id.history_info_back:
                finish();
                break;

        }
    }
}
